﻿//-----------------------------------------------------------------------
// <copyright file="GuildRankHelper.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Repository;
using GateShift.Common.Repository.Interfaces.DataInterfaces;
using GateShift.Common.Repository.Interfaces.Repositories;
using GateShift.Services.GameData.Entities;

#endregion

namespace GateShift.Testing.Services.GameData.Helpers
{
    /// <summary>
    /// Static Unit Test Helper Class for GuildRank Entities
    /// </summary>
    internal static class GuildRankHelper
    {
        /// <summary>
        /// Creates a completely random and unique guild rank name
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomGuildRankName()
        {
            return Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 20);
        }

        /// <summary>
        /// Creates a guild ready to save to the database
        /// </summary>
        /// <returns>GuildRank with unique default values</returns>
        public static IGuildRankData CreateGuildRank()
        {
            return CreateGuildRank(GuildHelper.CreateDBGuild().ID);
        }

        /// <summary>
        /// Creates a guild ready to save to the database
        /// </summary>
        /// <param name="guildID">GuildID to associate the rank with</param>
        /// <returns>GuildRank with unique default values</returns>
        public static IGuildRankData CreateGuildRank(Identity guildID)
        {
            GuildRank guildRank = new GuildRank
                                      {
                                          Name = CreateRandomGuildRankName(),
                                          IsLeader = false,
                                          GuildID = guildID
                                      };

            return guildRank;
        }

        /// <summary>
        /// Creates a guild rank ready pre-saved to the database
        /// </summary>
        /// <returns>GuildRank with unique default values</returns>
        public static IGuildRankData CreateDBGuildRank()
        {
            return CreateDBGuildRank(GuildHelper.CreateDBGuild().ID);
        }

        /// <summary>
        /// Creates a guild rank ready pre-saved to the database
        /// </summary>
        /// <param name="guildID">GuildID to associate the rank with</param>
        /// <returns>GuildRank with unique default values</returns>
        public static IGuildRankData CreateDBGuildRank(Identity guildID)
        {
            GuildRank guildRank = (GuildRank)CreateGuildRank(guildID);

            DBHelper.Provider.GetRepository<IGuildRankRepository>().Save(guildRank);

            return guildRank;
        }
    }
}